Aller au contenu principal

Capteurs latéraux

Les capteurs latéraux permettent de détecter des objets proches d'OLEM. Ils les voient jusqu'à 150 mm en ligne droite depuis le capteur. [insérer une image de la zone de détection]

Par commodité, le signal est déjà traité et l'API permet de :

  • vérifier si une main est à portée
  • vérifier si un élément de jeu est à portée [pourrait devenir obsolète]
  • obtenir la valeur du capteur en LSB ou en pourcentage

Le module fournit des constantes pour chaque côté, et des masques pour tester les valeurs renvoyées par ir_side_get_hand_mask() et ir_side_get_obstacle_mask().

Exemple​

Le signal du capteur avant est affiché : approchez et éloignez votre main. Voir aussi l'exemple de détection de la main.

import olem

start = olem.get_time_ms()
while olem.get_time_ms() - start < 20000:
value = olem.ir_side_get_sensor_value(olem.FRONT)
percent = olem.ir_side_get_sensor_percent(olem.FRONT)
print(str(value) + " LSB, " + str(percent) + "%")
olem.delay_ms(100)

Constantes et fonctions​

Constants​

ConstantValueDescription
FRONT0Front side of OLEM.
RIGHT1Right side of OLEM.
BACK2Back side of OLEM.
LEFT3Left side of OLEM.
FRONT_MASK1Bit of the front side in a side mask.
RIGHT_MASK2Bit of the right side in a side mask.
BACK_MASK4Bit of the back side in a side mask.
LEFT_MASK8Bit of the left side in a side mask.

ir_side_get_sensor_value(sensor)​

Get the signal of a side sensor. Side sensors see objects up to about 150 mm away.

ParameterDescription
sensorFRONT, RIGHT, BACK or LEFT

Returns: filtered signal in ADC units (LSB), it increases when an object gets closer

ir_side_get_sensor_percent(sensor)​

Get the signal of a side sensor as a percentage.

ParameterDescription
sensorFRONT, RIGHT, BACK or LEFT

Returns: from 0 when nothing is detected to 100 when an object is very close

ir_side_is_hand_present(side)​

Check if a hand is in front of a side sensor. A hand gives a weaker signal than an obstacle.

ParameterDescription
sideFRONT, RIGHT, BACK or LEFT

Returns: True if a hand is detected, False otherwise or if side is not valid

ir_side_is_obstacle_present(side)​

Check if an obstacle is in front of a side sensor. An obstacle gives a stronger signal than a hand.

ParameterDescription
sideFRONT, RIGHT, BACK or LEFT

Returns: True if an obstacle is detected, False otherwise or if side is not valid

ir_side_get_hand_mask()​

Returns: mask with the bit of each side where a hand is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK

ir_side_get_obstacle_mask()​

Returns: mask with the bit of each side where an obstacle is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK

ir_side_get_number_of_hands()​

Returns: number of sides where a hand is detected, from 0 to 4

ir_side_set_filter(value)​

Set the filter applied to the side sensors. A higher value makes them slower to react but more stable. The default value is 5.

ParameterDescription
valuefilter coefficient, 1 or more